#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int minSwaps(vector<int> &nums)
    {
        int n = nums.size();
        if (n <= 3)
            return 0;
        int total = accumulate(nums.begin(), nums.end(), 0);
        if (total >= n - 1) return 0;
        int ans = accumulate(nums.begin(), nums.begin() + total, 0);
        int t = ans;
        for(int head = 1; head < n; ++head){
            t -= nums[head - 1];
            t += nums[(head + total - 1) % n];
            ans = max(ans,t);
        }
        return total - ans;
    }
};

int main()
{

    // system("pause");
    return 0;
}
